package main

import "fmt"

type Person struct {
	name   string
	weight int
}

func (p Person) eat(food string) {
	fmt.Println("正在吃：", food)
}

type Address struct {
	city string
}

func (a Address) showCity() {
	fmt.Println(a.city)
}

type Student struct {
	Person         //类似于继承关系
	addr   Address //类似于增加了某个属性
	name   string  //Person 中拥有相同的属性
	age    int
}

//方法重写（Person中拥有相通的方法）
func (s Student) eat(food string) {
	fmt.Println("学生", s.name, "正在吃", food)
}

func main() {
	st1 := Student{
		Person: Person{name: "lisi", weight: 20},
		addr:   Address{city: "beijing"},
		name:   "zhangsan",
		age:    10,
	}
	fmt.Println("st1.name=", st1.name)
	fmt.Println("st1.Person.name=", st1.Person.name)
	fmt.Println("--------------------------------")
	fmt.Println("执行st1.eat(\"番茄\")")
	st1.eat("番茄")
	fmt.Println("--------------------------------")
	fmt.Println("st1.Person.eat(\"番茄\")")
	st1.Person.eat("番茄")
}
